package com.gnerv.rabbitmq.agent.command;

import com.gnerv.rabbitmq.agent.model.entity.Node;
import com.gnerv.rabbitmq.agent.tools.ExecTools;
import com.google.common.collect.Lists;
import lombok.Data;
import org.springframework.util.StringUtils;

import java.io.File;
import java.util.List;

/**
 * @author Gnerv LiGen
 */
@Data
public abstract class AbstractRabbitmqServerCommand extends AbstractRabbitmqCommand {

    private Node node;
    private List<String> commands;

    public final ExecTools.ExecResult run(List<String> commands) {
        List<String> commandlist = Lists.newArrayList();
        commandlist.add("sbin/rabbitmq-server");
        if (StringUtils.hasText(node.getName())) {
            commandlist.add("-n");
            commandlist.add(node.getName());
        }
        commandlist.addAll(commands);
        return ExecTools.run(commandlist, new File(node.getPath()));
    }

}